package top.jybill.service.Impl;

import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.jybill.dao.ISysLogDao;
import top.jybill.domain.MyPageInfo;
import top.jybill.domain.SysLog;
import top.jybill.service.ISysLogService;

import java.util.List;

@Service
public class ISysLogDaoServiceImpl implements ISysLogService {

  @Autowired
  private ISysLogDao sysLogDao;
  /**
   * 添加日志
   * @param log
   */
  public void addLog(SysLog log) {
    sysLogDao.addLog(log);
  }

  /**
   * 分页查询日志
   * @param pageInfo
   * @return
   */
  public MyPageInfo findLogsByPage(MyPageInfo pageInfo) {
    // query参数校验
    if (pageInfo.getQuery() == null || pageInfo.getQuery().length() < 1 || "null".equalsIgnoreCase(pageInfo.getQuery())) {
      pageInfo.setQuery(null);
    } else {
      pageInfo.setQuery("%" + pageInfo.getQuery() + "%");
    }

    // dao
    System.out.println(pageInfo);
    PageHelper.startPage(pageInfo.getPageNum(), pageInfo.getPageSize());
    List<SysLog> logs = sysLogDao.findLogsByPage(pageInfo);
    MyPageInfo retPage = new MyPageInfo(logs);
    System.out.println(retPage);
    return retPage;
  }
}
